/*
 * HttpHeader.cpp
 *
 *  Created on: 29-11-2011
 *      Author: cristian
 */

#include "HttpHeader.h"


HttpHeader::HttpHeader(string *get, string *host) {

	logger = new Logger;

	Get = "GET ";
	Host = "Host: ";
	Connection = "Connection: ";
	UserAgent = "User-Agent: ";
	Accept = "Accept: ";
	AcceptEncoding = "Accept-Encoding: ";
	AcceptLanguage = "Accept-Language: ";
	AcceptCharset = "Accept-Charset: ";

	if (get == NULL){
		GetValue = new string("");
	}else{
		GetValue = get;
	}
	if (host == NULL){
		HostValue = new string("");
	}else{
		HostValue = host;
	}

	ConnectionValue = new string("keep-alive");
	UserAgentValue = new string("Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.8 (KHTML, like Gecko) Chrome/17.0.942.0 Safari/535.8");
	AcceptValue = new string(" text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
	AcceptEncodingValue = new string(" gzip,deflate,sdch");
	AcceptLanguageValue = new string("en-US,en;q=0.8");
	AcceptCharsetValue = new string("ISO-8859-1,utf-8;q=0.7,*;q=0.3");
}

string *HttpHeader::getGetValue() const {
	return GetValue;
}

string *HttpHeader::getHostValue() const {
	return HostValue;
}

void HttpHeader::setGetValue(string *getValue) {
	GetValue = getValue;
}

void HttpHeader::setHostValue(string *hostValue) {
	HostValue = hostValue;
}



HttpHeader::~HttpHeader() {

	delete ConnectionValue;
	delete UserAgentValue;
	delete AcceptValue;
	delete AcceptEncodingValue;
	delete AcceptLanguageValue;
	delete AcceptCharsetValue;

}

string *HttpHeader::toString() {

	string* request = new string("");

	request->append(Get);
	request->append(*GetValue);
//	request->append(" HTTP/1.1");
	request->append("\r\n");
	request->append(Host);
	request->append(*HostValue);
	request->append("\r\n");
	request->append(Connection);
	request->append(*ConnectionValue);
	request->append("\r\n");
	request->append(UserAgent);
	request->append(*UserAgentValue);
	request->append("\r\n");
	request->append(Accept);
	request->append(*AcceptValue);
	request->append("\r\n");
	request->append(AcceptEncoding);
	request->append(*AcceptEncodingValue);
	request->append("\r\n");
	request->append(AcceptLanguage);
	request->append(*AcceptLanguageValue);
	request->append("\r\n");
	request->append(AcceptCharset);
	request->append(*AcceptCharsetValue);
	//request->append("\n");


	return request;
}

